﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;

namespace ThreadLearn
{
    internal static class TimerDemo
    {
        private static Timer s_timer;
        public static void Index()
        {
            Console.WriteLine("Checking status every 2 seconds");
            s_timer = new Timer(Status, null, Timeout.Infinite, Timeout.Infinite);
            s_timer.Change(0, Timeout.Infinite);
            Console.ReadLine();
        }

        private static void Status(Object state)
        {
            Console.WriteLine("In state at {0}", DateTime.Now);
            Thread.Sleep(1000);
            s_timer.Change(2000, Timeout.Infinite);
        } 

    }
}
